package com.example.demo.service.serviceImp;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.GitHub;
import com.example.demo.mapper.GitHubMapper;
import com.example.demo.service.GitHubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GitHubServiceImp implements GitHubService {
    @Autowired
    GitHubMapper gitHubMapper;

    @Override
    public Integer add(GitHub gitHub) {
        return gitHubMapper.insert(gitHub);
    }

    @Override
    public Integer delete(Integer id) {
        return gitHubMapper.deleteById(id);
    }

    @Override
    public Integer update(GitHub gitHub) {
        return gitHubMapper.updateById(gitHub);
    }

    @Override
    public Integer searchCount(GitHub gitHub) {
        return gitHubMapper.selectCount(null);
    }

    @Override
    public List<GitHub> search(Integer page, Integer limit, GitHub gitHub) {
        IPage<GitHub> gitHubPage = new Page<>(page, limit);//参数一是当前页，参数二是每页个数
        gitHubPage = gitHubMapper.selectPage(gitHubPage, null);
        return gitHubPage.getRecords();
    }
}
